package com.qf.leadnewswemedia.web.v1;

import com.qf.leadnewswemedia.service.WmMaterialService;
import com.qf.qfleadnewsmodel.commons.dtos.ResponseResult;
import com.qf.qfleadnewsmodel.wemedia.dtos.MaterialPageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/api/v1/material")
public class MaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    @PostMapping("/list")
    public ResponseResult list(@RequestBody MaterialPageDto materialPageDto){
        //确保分页参数正确
        materialPageDto.checkParam();

        return wmMaterialService.pageQuery(materialPageDto);
    }

    @PostMapping("/upload_picture")
    public ResponseResult uploadFile(MultipartFile multipartFile, HttpServletRequest request) throws IOException {
        return wmMaterialService.upload(multipartFile,request);
    }
}
